/*var viewedComments=new Array();
var viewedCommentsCount=0;
var hiddenComments=false;
var hiddenCommentsCount=0;

function viewComment(commentid){
	viewedComments[viewedCommentsCount]=commentid;
	viewedCommentsCount++;
}

function isViewed(commentid){
	for(var i=0;i<viewedCommentsCount;i++){
		if(viewedComments[i]==commentid){
			return true;
		}
	}
	viewComment(commentid);
	return false;
}

function showRepComment(divid){
	var repDiv=document.getElementById("repDiv"+divid);
	repDiv.style.display="";
	var repA=document.getElementById("repA"+divid);
	repA.style.display="none";
}*/

/**
 * @author Jairus Chan
 * 
 * @version 0.3
 */



var commentObjs = new Array();
var commentObjNum = 0;

AjaxComment = {
	objId : null,
	divWidth :640,
	arcCur : false,
	curClass : "curClass",
	curStyle : "curStyle",
	normalClass : "normalClass",
	normalStyle : "normalStyle",
	decStr : "%s",
	backFunc : "ajaxPageBack",
	errorFunc : null,
	beforeSendFunc : null,
	completeFunc : null,
	maxSize : 5,
	url : null,
	paramStr : null,
	hasParam : false,
	jumpFunc :"jumpTo",
	generateCommentInfoBar : function(objId) {
		var infobar = "<table width=\""
				+ AjaxComment.divWidth
				+ "\" cellspacing=\"0\" cellpadding=\"0\" height=\"28\" style=\"table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word;\">\n";
		infobar += "<tr bgcolor=\"#f2b600\">";
		infobar += "<td><font id=\"" + objId
				+ "Commentnum\" color=\"#ffffff\"></font></td>";
		infobar += "<td align=\"right\"><a id=\""+objId+"a_hideOrShowComments\" class=\"a_hideOrShowComments\" href=\"#\" onclick=\""
				+ objId + "Comment.hideOrShowComments()\">-</a>&nbsp;</td>";
		infobar += "</tr></table>";
		return infobar;
	},
	generateMyComment : function(objId) {
		var myComment = "";
		myComment += "<div id=\""
				+ objId
				+ "MyCommentDiv\">"
				+ "<font id=\""
				+ objId
				+ "CommentFont\" color=\"red\"></font>"
				+ "<div id=\""
				+ objId
				+ "RefCommentInfo\" style=\"display: none\"><b>&nbsp; "
				+ "<font id=\""
				+ objId
				+ "RefCommentInfoFont\" color=\"#004e90\"></font></b> "
				+ "<font id=\""
				+ objId
				+ "RefCommentCommetidFont\" style=\"display: none\">0</font> "
				+ "<a title=\"取消回复\" href=\"javascript:"
				+ objId
				+ "Comment.cancelRefComment()\">"
				+ "<img style=\"border: 0px\" alt=\"取消回复\" src=\""
				+ SKYLINE_DOMAIN
				+ "/img/commons/fail_min.gif\"></a></div>"
				+ "<div><table width='"
				+ AjaxComment.divWidth
				+ "' style=\"table-layout: fixed; WORD-BREAK: break-all; WORD-WRAP: break-word;\">"
				+ "<tr><td width='72' valign='top' align='center'>"
				+ "<div id=\"" + objId + "LoginedUserDiv\" ></div></td>"
				+ "<td align=\"right\" valign='top'>"
				+ "<textarea class='myComment' id=\"" + objId
				+ "MyComment\" cols=\"60\" rows=\"4\" onfocus=\"" + objId
				+ "Comment.showTools()\"></textarea>" + "<div id=\"" + objId
				+ "Tools\" style=\"display: none\"><a href=\"javascript:"
				+ objId + "Comment.insertSmiley()\">不能打开表情工具包</a></div>"
				+ "</td></tr></table></div>"
				+ "<div align=\"right\" style=\"width: " + AjaxComment.divWidth
				+ "px\"><br>";
		myComment += "<input class=\"btn_ok\" type=\"button\" onclick=\""
				+ objId + "Comment.commentResource()\" value=\"提交\">&nbsp;"
				+ "<input class=\"btn_cancel\" type=\"button\" onclick=\""
				+ objId
				+ "Comment.cancelComment()\" value=\"取消\">&nbsp;</div></div>";
		return myComment;
	},
	generatePageSetting : function(objId) {
		var setting = "pagination:new Pagination({arcCur:";
		var arc = AjaxComment.arcCur;
		setting += arc;
		setting += (",curClassStr:\"");
		setting += (AjaxComment.curClass);
		setting += ("\",curStyleStr:\"");
		setting += (AjaxComment.curStyle);
		setting += ("\",norClassStr:\"");
		setting += (AjaxComment.normalClass);
		setting += ("\",norStyleStr:\"");
		setting += (AjaxComment.normalStyle);
		setting += ("\",decStr:\"");
		setting += (AjaxComment.decStr);
		setting += ("\",pageObj:\"");
		setting += (objId);
		setting += ("\",maxSize:");
		setting += (AjaxComment.maxSize);
		setting += ("})");
		return setting;
	},
	generateAjaxBack : function(objId) {
		ajaxBack = AjaxComment.backFunc;
		ajaxBack += (":function(data){\n");
		ajaxBack += ("var page=data.page");
		ajaxBack += (";\n");
		ajaxBack += (AjaxComment.genDivUrlFunc(objId));
		ajaxBack += (objId + "Comment.processData");
		ajaxBack += ("(data);\n}\n");
		return ajaxBack;
	},
	genDivUrlFunc : function(objId) {

		var divUrlFunc = "jQuery('#";
		divUrlFunc += (objId + "PageDivTop");
		divUrlFunc += ("').html(");
		divUrlFunc += (objId);
		divUrlFunc += (".pagination.generateTotalStr(page));\n");

		divUrlFunc += ("jQuery('#");
		divUrlFunc += (objId + "PageDivBottom");
		divUrlFunc += ("').html(");
		divUrlFunc += (objId);
		divUrlFunc += (".pagination.generateTotalStr(page));\n");

		return divUrlFunc;
	},
	generateAjaxAsk : function(objId, curpage, url) {
		//var objId=objId
		//var before="$(\"#" + objId + "Commentlist\").html(\"正在载入评论...\");"
		var ajaxAsk = ("doAjax('");
		ajaxAsk += (url);
		ajaxAsk += ("','");
		if (AjaxComment.paramStr == null) {
			ajaxAsk += ("curpage='+");
			ajaxAsk += (curpage);
		} else {
			if (AjaxComment.hasParam) {
				ajaxAsk += (AjaxComment.paramStr);
				ajaxAsk += ("&curpage='+");
				ajaxAsk += (curpage);
			} else {
				ajaxAsk += ("curpage='+");
				ajaxAsk += (curpage);
			}
		}
		ajaxAsk += (",");
		ajaxAsk += (objId);
		ajaxAsk += (".");
		ajaxAsk += (AjaxComment.backFunc);
		if (AjaxComment.errorFunc != null) {
			ajaxAsk += (",");
			ajaxAsk += (AjaxComment.errorFunc);
		}
		if (AjaxComment.beforeSendFunc != null) {
			ajaxAsk += (",");
			ajaxAsk += AjaxComment.beforeSendFunc;
			//"function(){$(\"#" + objId + "Commentlist\").html(\"正在载入评论...\");}";
		}
		if (AjaxComment.completeFunc != null) {
			ajaxAsk += (",");
			ajaxAsk += (AjaxComment.completeFunc);
		}
		ajaxAsk += (");");
		return ajaxAsk;
	},
	generateFirstAskFunc : function(objId, url) {
		var firstAskFunc = "firstFunc";
		firstAskFunc += (":function(){\n $(\"#" + objId + "Commentlist\").html(\"<tr><td width='72'></td><td>正在载入评论...</td></tr>\"); return ");
		firstAskFunc += (AjaxComment.generateAjaxAsk(objId, "1", url));
		firstAskFunc += ("\n}\n");
		return firstAskFunc;
	},
	generateJumpTo : function(objId,url) {
		var  jumpFunc = AjaxComment.jumpFunc;
		jumpFunc+=(":function")+("(i){\n $(\"#" + objId + "Commentlist\").html(\"<tr><td width='72'></td><td>正在载入评论...</td></tr>\");");
		jumpFunc+=(AjaxComment.generateAjaxAsk(objId,"i",url));
		jumpFunc+=("\n}\n");
		return jumpFunc;
	},
	generateComment : function(objId, resourceId, resourceName, commentType,
			ownerId) {

		var commentResourceURL = SKYLINE_DOMAIN + "/comment/commentResource/"
				+ commentType + "/" + resourceId + ".html";
		var commentAgreeURL = SKYLINE_DOMAIN + "/comment/" + commentType
				+ "/vote/AGREE/" + resourceId + ".html";
		var commentDisagreeURL = SKYLINE_DOMAIN + "/comment/" + commentType
				+ "/vote/DISAGREE/" + resourceId + ".html";
		var commentDeleteURL = SKYLINE_DOMAIN + "/comment/" + commentType
				+ "/delete" + ".html";
		var comment = "  " + objId + "Comment = new Comment();";
		if(commentType=="SHORTMESSAGE"){
			comment += objId + "Comment.resourceId=\'" + resourceId + "\';\n";
		}else{
			comment += objId + "Comment.resourceId=" + resourceId + ";\n";
		}
		comment += objId + "Comment.resourceName=\"" + resourceName + "\";\n";
		comment += objId + "Comment.type=\"" + commentType + "\";\n";
		// comment += objId + "Comment.loginedUserId=" + loginedUserId+";\n";
		comment += objId + "Comment.ownerId=" + ownerId + ";\n";

		comment += objId + "Comment.commentResourceURL=\"" + commentResourceURL
				+ "\";\n";
		comment += objId + "Comment.agreeURL=\"" + commentAgreeURL + "\";\n";
		comment += objId + "Comment.disagreeURL=\"" + commentDisagreeURL
				+ "\";\n";
		comment += objId + "Comment.deleteURL=\"" + commentDeleteURL + "\";\n";
		// comment += objId + "Comment.getLoginedUserURL=\"" + contextPath +
		// "/getlogineduser.html\";\n";
		comment += objId + "Comment.objId=\"" + objId + "\";\n";
		comment += objId + "Comment.commentAjax=" + objId + ";\n";
		comment += objId + "Comment.divWidth=" + AjaxComment.divWidth + ";\n";
		return comment;
	},
	generateReady : function(objId) {
		return "jQuery(\"document\").ready(function(){" + objId
				+ ".firstFunc();});";
	},
	generateAllHTML : function(objId, resourceId, resourceName, commentType,
			ownerId) {
		var html = "";
		html += AjaxComment.generateCommentInfoBar(objId);
		html += ("<div id=\"" + objId + "PageDivTop\" style=\"width: "
				+ AjaxComment.divWidth + "px\" align=\"right\" ></div>");
		html += ("<table id=\"" + objId + "Commentlist\"  width=\""
				+ AjaxComment.divWidth + "\" cellspacing=\"0\" cellpadding=\"0\" style=\"FONT-SIZE: 14px;LINE-HEIGHT: 16pt ;table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word;\"></table>");
		html += (AjaxComment.generateMyComment(objId));
		return html;
	},
	generateAllscript : function(objId, resourceId, resourceName, commentType,
			ownerId) {
		var url = SKYLINE_DOMAIN + "comment/getComment/" + commentType + "/"
				+ resourceId + "/" + 8 + ".html";
		var script = "";
		script += ("var usingComment;");
	//	script += (" ");
		script += (objId);
		script += ("={\n");
		script += (AjaxComment.generatePageSetting(objId));
		script += (",\n");
		script += (AjaxComment.generateAjaxBack(objId));
		script += (",\n");
		script += (AjaxComment.generateFirstAskFunc(objId, url));
		script += (",\n");
		script += (AjaxComment.generateJumpTo(objId,url));
		script += ("}\n;");
		script += (AjaxComment.generateComment(objId, resourceId, resourceName,
				commentType, ownerId));
		script += (AjaxComment.generateReady(objId));
		script += ("commentObjs[commentObjNum]=" + objId + "Comment;commentObjNum++;");
		return script;
	}
};

function Comment() {
	this.objId = "";
	this.resourceId = 0;
	this.resourceName = "";
	this.type = "";
	this.loginedUserId = 0;
	this.ownerId = "";

	this.commentResourceURL = "";
	this.agreeURL = "";
	this.disagreeURL = "";
	this.deleteURL = "";
	// this.getLoginedUserURL="";
	this.commentAjax = null;
	this.divWidth = 640;

	this.getRefComments = function(ref, width) {
		var showRep = "";
		var repDivHead = "";
		var repDivTail = "";
		if (ref == null) {
			hiddenComments = false;
			return "";
		}
		if (width > 480) {
			width = width - 6;
			return showRep
					+ repDivHead
					+ "<div style='height:2px'></div><div align='center' style='width:"
					+ width + "px; border: 1px solid #ccccbb; height:auto'>"
					+ this.getRefComments(ref.refComment, width)
					+ this.getCommentInfo(ref, width - 6)
					+ this.getContent(ref, width - 6) + "</div>" + repDivTail;
		} else {
			return showRep
					+ repDivHead
					+ "<div style='height:2px'></div><div align='center' style='width:"
					+ width
					+ "px; border-top: 1px solid #ccccbb; border-bottom: 1px solid #7a7a7a;border-left: 0px;border-right:0px;height:auto'>"
					+ this.getRefComments(ref.refComment, width)
					+ this.getCommentInfo(ref, width - 6)
					+ this.getContent(ref, width - 6) + "</div>" + repDivTail;
		}
	};

	this.getNickname = function(curComment) {
		return "<a class='nickname' href='home/" + curComment.commenterId
				+ ".html'>" + curComment.commenterNickname + "</a>";
	};

	this.getCommentInfo = function(curComment, width) {
		var info = "<div align='left'style='width:" + width + "px'>"
				+ this.getNickname(curComment);
		info = info + "<font color='#6a6a6a' style='FONT-SIZE: 12px;'>发表于"
				+ this.getCreateTime(curComment.createTime) + "</font></div>";
		return info;
	};

	this.getContent = function(comment, width) {
		var commentContent = comment.content;
		commentContent = commentContent.clean();
		for ( var i = 0; i < smileys.length; i++) {
			var reg = "/" + smileys[i];
			var rep = "<img lt='" + smileysChn[i] + "' src='" + smileysPath
					+ smileys[i] + ".gif'>";
			commentContent = commentContent.replaceAll(reg, rep);
		}
		return "<div align='left' style='width:" + width + "px'>"
				+ commentContent + "</div>";
	};

	this.getBgColor = function(i) {
		var bgcolor = "#ffffff";
		if (i % 2 == 1)
			bgcolor = "#efefef";
		return bgcolor;
	};

	this.getDeleteBtn = function(commentId, resourceId,commentOwner, resourceOwner,
			loginedUserId) {
		if (loginedUserId == null || loginedUserId == 0) {
			return "";
		} else if (commentOwner != loginedUserId
				&& resourceOwner != loginedUserId) {
			return "";
		} else {
			return "<a href='javascript:" + this.objId
					+ "Comment.deleteThisComment(" + commentId+",\""+resourceId
					+ "\")' class='a_deleteComment'>删除</a>&nbsp;";
		}
	};

	this.deleteThisComment = function(commentId,resourceId) {
		usingComment = this;
		if (confirm('你确定删除这条评论吗?\n\n提示:删除评论后将不可恢复') == true) {
			$
					.ajax({
						url : this.deleteURL,
						data : "commentid=" + commentId+"&resourceid="+resourceId,
						type : "POST",
						dataType : "json",
						contentType : "application/x-www-form-urlencoded; charset=utf-8",
						success : function(msg) {
							usingComment.commentAjax.firstFunc();
						}
					});
		}
	};

	this.hideOrShowComments = function() {
		var commentlist = document.getElementById(this.objId + "Commentlist");
		var pageDiv = document.getElementById(this.objId + "PageDivTop");
		var myCommentDiv = document.getElementById(this.objId + "MyCommentDiv");
		if (commentlist.style.display == "none") {
			commentlist.style.display = "block";
			pageDiv.style.display = "block";
			if(myCommentDiv!=null){
				myCommentDiv.style.display = "block";
			}
			document.getElementById(this.objId +"a_hideOrShowComments").innerHTML = "-";
		} else {
			commentlist.style.display = "none";
			pageDiv.style.display = "none";
			if(myCommentDiv!=null){
				myCommentDiv.style.display = "none";
			}
			document.getElementById(this.objId +"a_hideOrShowComments").innerHTML = "+";
		}
	};

	this.refThisComment = function(nickname, commentid) {
		document.getElementById(this.objId + "RefCommentInfo").style.display = "block";
		document.getElementById(this.objId + "RefCommentInfoFont").innerHTML = "回复"
				+ nickname + ":";
		document.getElementById(this.objId + "RefCommentCommetidFont").innerHTML = commentid;
		document.getElementById(this.objId + "MyComment").focus();
	};

	this.cancelRefComment = function() {
		document.getElementById(this.objId + "RefCommentInfo").style.display = "none";
		document.getElementById(this.objId + "RefCommentInfoFont").innerHTML = "";
		document.getElementById(this.objId + "RefCommentCommetidFont").innerHTML = 0;
	};

	this.processData = function(msg) {
		//alert();
		this.getLoginedUser();
		// viewedCommentsCount=0;
		hiddenComments = false;
		// hiddenCommentsCount=0;
		var comments = msg.data;
		var page = msg.page;
		var commentnum = "&nbsp;已有" + page.total + "条评论";
		document.getElementById(this.objId + "Commentnum").innerHTML = commentnum;
		// alert(this.loginedUserId);
		// 清除commentlist中原来的数据
		$("#" + this.objId + "Commentlist").html("");
		for ( var i = 0; i < comments.length; i++) {
			var width = this.divWidth - 72;
			var curComment = comments[i];
			var bgcolor = this.getBgColor(i);
			// comment.viewed=true;
			// 输入出用户的头像与昵称
			var content = "<tr bgcolor="
					+ bgcolor
					+ "><td width='72' valign='top' align='center'><div style='height:10px'></div><img src='"
					+ portraitPath + curComment.commenterPortrait
					+ "' width='48px' height='48px'/></td>";
			content = content + "<td width='" + width
					+ "'><font style='FONT-SIZE: 14px;'>"
					+ this.getNickname(curComment) + "发表于"
					+ this.getCreateTime(curComment.createTime) + "</font><br>";
			var ref = curComment.refComment;
			// 输出盖楼
			content = content + "<div class='commentContent'>"
					+ this.getRefComments(ref, width);
			// 输出用户的评论
			content = content + this.getContent(curComment, width) + "</div>";// ++"</div></td></tr>";
			content = content
					+ "<p align='right' valign='center' style='margin:0px 0;padding:0px 0;font-size:12px;' >";
			content = content + "<a id='" + curComment.id
					+ "AgreeA' class='a_agree' href='javascript:" + this.objId
					+ "Comment.commentAgree(" + curComment.id + ","
					+ curComment.agreeNum + ")'>赞成</a>(<font id='"
					+ curComment.id + "AgreeFont'>" + curComment.agreeNum
					+ "</font>)&nbsp;";
			content = content + "<a id='" + curComment.id
					+ "DisagreeA' class='a_disagree' href='javascript:"
					+ this.objId + "Comment.commentDisagree(" + curComment.id
					+ "," + curComment.disagreeNum + ")'>反对</a>(<font id='"
					+ curComment.id + "DisagreeFont'>" + curComment.disagreeNum
					+ "</font>)&nbsp;";
			if (this.loginedUserId != 0)
				content = content + "<a class='a_reply'  href='javascript:"
						+ this.objId + "Comment.refThisComment(\""
						+ curComment.commenterNickname + "\"," + curComment.id
						+ ") '>回复</a>&nbsp;";
			content = content
					+ this.getDeleteBtn(curComment.id,curComment.resourceId, curComment.commenterId,
							curComment.ownerId, this.loginedUserId);
			content = content + "</p></div></td></tr>";
			$("#" + this.objId + "Commentlist").append(content);
			// alert(this.objId);
		}
	};

	this.getCreateTime = function(createTime) {
		//var now = new Date();
		var createTime = new Date(createTime);
		/*
		 * if(now.getFullYear()==createTime.getFullYear()&&now.getMonth()==createTime.getMonth()&&now.getDay()==createTime.getDay()){
		 * if(now.getHours()==createTime.getHours()){
		 * if(now.getMinutes()==createTime.getMinutes()){ return "刚刚"; }else
		 * if(now.getMinutes()>createTime.getMinutes()){ return
		 * (now.getMinutes()-createTime.getMinutes())+"分钟前"; } }else
		 * if(now.getHours()>createTime.getHours()){ return
		 * (now.getHours()-createTime.getHours())+"小时前"; } }
		 */

		// var today = new Date();
		// alert(today.format("yyyy-MM-dd"));
		return createTime.format("yyyy-MM-dd hh:mm:ss");
	};

	this.doError = function(msg) {
		alert(msg);
	};

	this.checkComment = function(commentContent) {
		// alert(commentContent);
		var commentFont = document.getElementById(this.objId + "CommentFont");
		if (commentContent.length <= 1) {
			commentFont.innerHTML = "<img src='" + sorryGifPath
					+ "'/>嗳,你让我为难了,请输入评论吧.";
			return false;
		} else if (commentContent.length >= 200) {
			commentFont.innerHTML = "<img src='" + sorryGifPath
					+ "'/>嗳,您最多也只能输入200个字.";
			return false;
		} else {
			commentFont.innerHTML = "";
			return true;
		}
	};

	this.commentResource = function() {
		var commentContent = document.getElementById(this.objId + "MyComment").value;
		var refComment = document.getElementById(this.objId
				+ "RefCommentCommetidFont").innerHTML;

		var data = "resourceName=" + this.resourceName + "&commentContent="
				+ commentContent + "&refComment=" + refComment
				+ "&resourceOwner=" + this.ownerId;

		var commentToSource = document.getElementById(this.objId
				+ "CommentToSource");
		var shareResourceId = null;
		var shareOwnerId = null;

		if (commentToSource && commentToSource.checked) {

			shareResourceId = document.getElementById(this.objId
					+ "ShareResourceId").value;
			shareOwnerId = document.getElementById(this.objId + "ShareOwnerId").value;
			shareCommentType = document.getElementById(this.objId
					+ "ShareCommentType").value;
			data += "&shareResourceId=" + shareResourceId + "&shareOwnerId="
					+ shareOwnerId + "&shareCommentType=" + shareCommentType;
			// alert(shareResourceId);
		}
		usingComment = this;
		if (this.checkComment(commentContent) == true) {
			var url = this.commentResourceURL;
			$
					.ajax({
						url : url,
						data : data,
						type : "POST",
						dataType : "json",
						contentType : "application/x-www-form-urlencoded; charset=utf-8",
						success : function(msg) {
							usingComment.commentAjax.firstFunc();
							// alert("提交成功!");
							usingComment.cancelRefComment();
							// comment.cancelComment(myComment)
							usingComment.cancelComment();
							// window.location.href='#';
						}
					});
		}
	};

	this.cancelComment = function() {
		var commentContent = document.getElementById(this.objId + "MyComment");
		commentContent.value = "";
	};

	this.commentAgree = function(commentid, agree) {
		$.ajax({
			url : this.agreeURL,
			data : "commentid=" + commentid,
			type : "POST",
			dataType : "json",
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			success : function(msg) {
				var agreeFont = document
						.getElementById(commentid + "AgreeFont");
				var agreeA = document.getElementById(commentid + "AgreeA");
				agreeFont.innerHTML = (agree + 1);
				agreeA.href = "javascript:";
				agreeA.className = "a_fail";
//				var disagreeFont = document.getElementById(commentid
//						+ "DisagreeFont");
				var disagreeA = document
						.getElementById(commentid + "DisagreeA");
				disagreeA.href = "javascript:";
				disagreeA.className = "a_fail";
			}
		});
	};

	this.commentDisagree = function(commentid, disagree) {
		$.ajax({
			url : this.disagreeURL,
			data : "commentid=" + commentid,
			type : "POST",
			dataType : "json",
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			success : function(msg) {
				var disagreeFont = document.getElementById(commentid
						+ "DisagreeFont");
				var disagreeA = document
						.getElementById(commentid + "DisagreeA");
				disagreeFont.innerHTML = (disagree + 1);
				disagreeA.href = "javascript:";
				disagreeA.className = "a_fail";
				var agreeFont = document
						.getElementById(commentid + "AgreeFont");
				var agreeA = document.getElementById(commentid + "AgreeA");
				agreeA.href = "javascript:";
				agreeA.className = "a_fail";
			}
		});
	};

	this.doNoting = function() {
	};

	/*
	 * function showLoginDiv(){ var loginA = document.getElementById("loginA");
	 * var loginDiv = document.getElementById("loginDiv");
	 * loginDiv.style.display="block"; loginA.style.display="none"; }
	 * 
	 * function hideLoginDiv(){ var loginA = document.getElementById("loginA");
	 * var loginDiv = document.getElementById("loginDiv");
	 * loginDiv.style.display="none"; loginA.style.display="none"; }
	 */

	/*
	 * this.login=function(){ var email = document.getElementById("email"); var
	 * password = document.getElementById("password"); $.ajax({ url:
	 * ajaxloginURL, data:"email="+email.value+"&password="+password.value, type :
	 * "POST", dataType:"json", contentType: "application/x-www-form-urlencoded;
	 * charset=utf-8", success : function(msg){ var commentFont =
	 * document.getElementById("commentFont"); if(msg=="true"){
	 * commentFont.innerHTML="登陆成功！"; hideLoginDiv(); getLoginedUser(); }else{
	 * commentFont.innerHTML="登陆失败！"; } } }); }
	 */

	this.showTools = function() {
		var tools = document.getElementById(this.objId + "Tools");
		tools.style.display = "block";
		this.getSmileys(tools);
	};

	this.hideTools = function() {
		// var commentContent=document.getElementById("myComment").value;
		// var tools = document.getElementById("tools");
		// if(commentContent<1)
		// tools.style.display="none";
	};

	this.getSmiley = function(i) {
		var smileyA = "<a title='" + smileysChn[i] + "' href='javascript:"
				+ this.objId + "Comment.insertSmiley(\"" + smileys[i]
				+ "\")'><img style='border: 1px #eeeeee' src='" + smileysPath
				+ smileys[i] + ".gif' width='24px' height='24px'></a>";
		return smileyA;
	};

	this.getSmileys = function(tools) {
		// var tools = document.getElementById("tools");
		var smileyA = "";
		for ( var i = 0; i < smileys.length; i++) {
			// var smiley=smileys[i];
			smileyA += this.getSmiley(i);
			// tools.innerHTML+=smileyA;
		}
		tools.innerHTML = smileyA;
	};

	this.insertSmiley = function(smiley) {
		var commentContent = document.getElementById(this.objId + "MyComment");
		commentContent.value += "/" + smiley;
	};

	this.getLoginedUser = function() {
		var loginedUserDiv = document.getElementById(this.objId
				+ "LoginedUserDiv");
		var myCommentDiv = document.getElementById(this.objId + "MyCommentDiv");
		/*
		 * $.ajax({ url: this.getLoginedUserURL, data:null, type : "POST",
		 * dataType:"json", contentType: "application/x-www-form-urlencoded;
		 * charset=utf-8", success : function(msg){ if(msg!=null&&msg.id!=0) {
		 * myCommentDiv.style.display=""; loginedUserDiv.innerHTML="<img
		 * src='"+portraitPath+"/"+msg.portrait+"' width='54px'
		 * height='54px'>"; }else{ myCommentDiv.style.display="none"; } } });
		 */
		if (loginedUser != null && loginedUser.id != 0) {
			// alert();
			myCommentDiv.style.display = "";
			loginedUserDiv.innerHTML = "<img src='" + portraitPath + "/"
					+ loginedUser.portrait
					+ "' width='54px' height='54px'>";
			this.loginedUserId = loginedUser.id;
		} else {
			// alert(loginedUser);
			myCommentDiv.style.display = "none";
		}
	};

}

Date.prototype.format = function(style) {
	var o = {
		"M+" : this.getMonth() + 1, // month
		"d+" : this.getDate(), // day
		"h+" : this.getHours(), // hour
		"m+" : this.getMinutes(), // minute
		"s+" : this.getSeconds(), // second
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		"S" : this.getMilliseconds()
	// millisecond
	};
	if (/(y+)/.test(style)) {
		style = style.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	}
	for ( var k in o) {
		if (new RegExp("(" + k + ")").test(style)) {
			style = style.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return style;
};
